# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/16 10:22
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : Gaussian_noise.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage import util
from pydicom import dcmread
from DIP_experiment_5.util import contrast_show
from PIL import ImageFilter, Image
im_path = "../experiment_fig/CT000009"
font_path = "C:/Windows/Fonts/simhei.ttf"
im = dcmread(im_path)
im_arr = im.pixel_array  # 3044 -2000
gray_range = im_arr.max() - im_arr.min()
# 生成高斯噪声图像数组
# gaussian_noise = util.random_noise(im_arr, mode='gaussian') * gray_range
# 带高斯噪声的image对象
noise_im = Image.fromarray(im_arr).convert("L")
# 5x5均值滤波
blur_im = noise_im.filter(ImageFilter.BLUR)
# 5x5高斯滤波
gaussian_blur_im = noise_im.filter(ImageFilter.GaussianBlur(2))
# 5x5中值滤波
median_blur_im = noise_im.filter(ImageFilter.MedianFilter(size=5))
im_dict = {"原始图像": im_arr,  "5x5均值滤波图像": blur_im,
           "5x5高斯滤波图像": gaussian_blur_im, "5x5中值滤波图像": median_blur_im}
contrast_show(im_dict, (2, 2), hspace=0.4, font=font_path)
